//
//  SmallHeader.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/15.
//

#import "SmallHeader.h"
#import "UIView+AZGradient.h"
#import <SDWebImage/SDWebImage.h>

@interface  SmallHeader()
@property(nonatomic,strong)UIImageView *bg;
@property(nonatomic,strong)UIImageView *logo;
@property(nonatomic,strong)UIImageView *user_icon;
@property(nonatomic,strong)UIImageView *tipImg;
@property(nonatomic,strong)UIImageView *apply;
@property(nonatomic,strong)UILabel *applytext;
@property(nonatomic,strong)UILabel *mLabel;
@property(nonatomic,strong)UILabel *tLabel;
@property(nonatomic,strong)NSString *pid;
@property(nonatomic,strong)UILabel *name;
@property (nonatomic,strong)UILabel *t;
@property (nonatomic,strong)UILabel *t1;
@property (nonatomic,strong)UILabel *m;
@property (nonatomic,strong)UILabel *m1;

@end
@implementation SmallHeader

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =UIColor.clearColor;
        [self setUpUI];
    }
    return self;
}


-(void)setUpUI{
    [self addSubview:self.bg];
    [_bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.height.mas_equalTo(KWidth(400)+MarginTop);
    }];
    [self addSubview:self.tLabel];
    [_tLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bg.mas_bottom).offset(10);
        make.left.mas_offset(13);
    }];
}
-(UIImageView *)bg
{
    if(!_bg){
        _bg = [UIImageView new];
        _bg.userInteractionEnabled = YES;
        _bg.image = [UIImage imageNamed:@"home_small_bg"];
        _bg.contentMode = UIViewContentModeScaleToFill;
//        [_bg addSubview:self.logo];
//        [_logo mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_offset(MarginTop+20+10);
//            make.left.mas_offset(13);
//            make.size.mas_equalTo(CGSizeMake(36, 36));
//        }];
//        [_bg addSubview:self.name];
//        [_name mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerY.mas_equalTo(_logo);
//            make.left.equalTo(_logo.mas_right).offset(5);
//        }];

        CGFloat height = 0.0;
        if (@available(iOS 13.0, *)) {
            NSSet *set = [UIApplication sharedApplication].connectedScenes;
            UIWindowScene *windowScene = [set anyObject];
            UIStatusBarManager *statusBarManager = windowScene.statusBarManager;
            CGFloat topHeight = statusBarManager.statusBarFrame.size.height;
            height = topHeight ? topHeight : 20.0;
        }else {
            height = [[UIApplication sharedApplication] statusBarFrame].size.height;
        }
        
        UIView *view = [UIView new];
        [_bg addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(64);
            make.left.mas_offset(0);
            make.right.mas_offset(0);
        }];
        UIImageView *img = [UIImageView new];
        img.image = [UIImage imageNamed:@"home_small_tbg"];
        [view addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_offset(0);
            make.left.mas_offset(14);
            make.right.mas_offset(-14);
        }];
        [view addSubview:self.mLabel];
        [_mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.mas_equalTo(view);
            make.top.mas_offset(49);
            make.left.mas_offset(90);
        }];
        UILabel *l = [UILabel new];
        l.textColor = HexColor(@"#303030");
        l.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
        l.text = @"Loan amount(₱)";
        [view addSubview:l];
        [l mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_mLabel.mas_bottom).offset(12);
            make.left.mas_equalTo(_mLabel);
        }];
//        [_bg addSubview:self.user_icon];
//        [_user_icon mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_offset(-14);
//            make.centerY.mas_equalTo(_logo);
//        }];
//        [_bg addSubview:self.tipImg];
//        [_tipImg mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.bottom.mas_offset(0);
//            make.size.mas_equalTo(CGSizeMake(137, 172));
//        }];
        [view addSubview:self.t];
        [_t mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_offset(28);
//            make.left.mas_offset(13);
            make.top.equalTo(l.mas_bottom).offset(80);
            make.left.mas_offset(70);
        }];
        [view addSubview:self.t1];
        [_t1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_t.mas_bottom).offset(5);
            make.centerX.mas_equalTo(_t);
        }];
        
        [view addSubview:self.m];
        [_m mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.mas_offset(80);
//            make.right.mas_offset(-25);
            make.top.equalTo(l.mas_bottom).offset(80);
            make.right.mas_offset(-70);
        }];
        [view addSubview:self.m1];
        [_m1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_m.mas_bottom).offset(5);
            make.centerX.mas_equalTo(_m);
        }];

        [view addSubview:self.applytext];
        [_applytext mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(view);
//            make.left.mas_offset(5);
            make.bottom.mas_offset(-20);
        }];
        [view addSubview:self.apply];
        [_apply mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.bottom.mas_offset(-10);
            make.size.mas_equalTo(CGSizeMake(15, 17));
            make.left.equalTo(_applytext.mas_right).offset(5);
            make.centerY.mas_equalTo(_applytext);
        }];


        
//        [_bg addSubview:self.mLabel];
//        [_mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.mas_equalTo(_bg);
//            make.top.mas_offset(60 + height);
//        }];
//        
//        [_bg addSubview:self.user_icon];
//        [_user_icon mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.mas_offset(-14);
//            make.centerY.mas_equalTo(_logo);
//        }];
//        [_bg addSubview:self.tipImg];
//        [_tipImg mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.bottom.mas_offset(0);
//            make.size.mas_equalTo(CGSizeMake(137, 172));
//        }];
//        [_bg addSubview:self.apply];
//        [_apply mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.bottom.mas_offset(-10);
//            make.size.mas_equalTo(CGSizeMake(98, 98));
//        }];
        UIButton *btn = [UIButton new];
        [_bg addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_offset(0);
        }];
        [btn addTarget:self action:@selector(applyClick:) forControlEvents:UIControlEventTouchUpInside];
//        _user_icon.userInteractionEnabled = YES;
//        UIButton *hbtn = [[UIButton alloc]init];
//        [_user_icon addSubview:hbtn];
//        [hbtn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.left.right.bottom.mas_offset(0);
//        }];
//        [_bg bringSubviewToFront:_user_icon];
//        [hbtn addTarget:self action:@selector(headerClick1) forControlEvents:UIControlEventTouchUpInside];

    }
    return _bg;
}
-(void)headerClick1{
    if (self.headerClick) {
        self.headerClick();
    }
}

-(void)applyClick:(UIButton *)sender{
    if (self.applyAction) {
        self.applyAction(self.pid);
    }
}
-(UILabel *)name
{
    if (!_name) {
        _name = [UILabel new];
        _name.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
        _name.textColor = HexColor(@"#0B9700");
    }
    return _name;
}

-(UIImageView *)logo
{
    if(!_logo){
        _logo = [UIImageView new];
        _logo.image = [UIImage imageNamed:@"logo"];
        _logo.contentMode = UIViewContentModeScaleAspectFit;
        _logo.layer.masksToBounds = YES;
        _logo.layer.cornerRadius = 5;
    }
    return _logo;
}
-(UIImageView *)user_icon{
    if(!_user_icon){
        _user_icon = [UIImageView new];
        _user_icon.image = [UIImage imageNamed:@"user"];
        _user_icon.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _user_icon;
}
-(UIImageView *)tipImg
{
    if(!_tipImg){
        _tipImg = [UIImageView new];
        _tipImg.image = [UIImage imageNamed:@"tips"];
        _tipImg.contentMode = UIViewContentModeScaleAspectFit;
        [_tipImg addSubview:self.t];
        [_t mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(24);
            make.left.mas_offset(13);
        }];
        [_tipImg addSubview:self.t1];
        [_t1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_t.mas_bottom).offset(0);
            make.centerX.mas_equalTo(_t);
        }];
        
        [_tipImg addSubview:self.m];
        [_m mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(80);
            make.right.mas_offset(-25);
        }];
        [_tipImg addSubview:self.m1];
        [_m1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_m.mas_bottom).offset(0);
            make.centerX.mas_equalTo(_m);
        }];


    }
    return _tipImg;
}
-(UIImageView *)apply
{
    if (!_apply) {
        _apply = [UIImageView new];
        _apply.image = [UIImage imageNamed:@"home_bg_apply"];
    }
    return _apply;
}
-(UILabel *)applytext
{
    if (!_applytext) {
        _applytext = [UILabel new];
        _applytext.textAlignment = NSTextAlignmentCenter;
        _applytext.textColor = HexColor(@"#ffffff");
        _applytext.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
    }
    return _applytext;
}
-(UILabel *)mLabel
{
    if (!_mLabel) {
        _mLabel = [UILabel new];
//        _mLabel.text = @"₱ 80,000";
        _mLabel.textColor = HexColor(@"#333333");
        _mLabel.font = [UIFont systemFontOfSize:44 weight:UIFontWeightBold];
    }
    return _mLabel;
}
-(UILabel *)tLabel
{
    if (!_tLabel) {
        _tLabel = [UILabel new];
        _tLabel.text = @"Loan supermarket";
        _tLabel.textColor = HexColor(@"#141C35");
        _tLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    }
    return _tLabel;
    
}
-(void)setSource:(NSDictionary *)source
{
    
}
-(void)setItem:(NSDictionary *)item
{
    _t.text =item[@"spokes"][0][@"trouble"] ;
    _t1.text = item[@"spokes"][0][@"earthquake"] ;
    _m.text  = item[@"spokes"][0][@"remarkedive"] ;
    _m1.text = item[@"spokes"][0][@"toward"] ;
    _pid = [NSString stringWithFormat:@"%@",item[@"spokes"][0][@"adjadjadj"]];
    _mLabel.text = item[@"spokes"][0][@"voicethe"];
    _applytext.text = item[@"spokes"][0][@"deckwhat"];
    [_logo sd_setImageWithURL:[NSURL URLWithString:CPS(item[@"spokes"][0][@"sorrow"])] placeholderImage:[UIImage imageNamed:@"logo"]];
    _name.text = CPS(item[@"spokes"][0][@"continued"]);
}

-(UILabel *)t
{
    if (!_t) {
        _t = [UILabel new];
        _t.textColor = HexColor(@"#333333");
        _t.font  = [UIFont systemFontOfSize:14];
    }
    return _t;
}
-(UILabel *)t1
{
    if (!_t1) {
        _t1 = [UILabel new];
        _t1.textColor = HexColor(@"#333333");
        _t1.font  = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    }
    return _t1;
}
-(UILabel *)m{
    if (!_m) {
        _m = [UILabel new];
        _m.textColor = HexColor(@"#333333");
        _m.font  = [UIFont systemFontOfSize:14];
    }
    return _m;
}
-(UILabel *)m1
{
    if (!_m1) {
        _m1 = [UILabel new];
        _m1.textColor = HexColor(@"#333333");
        _m1.font  = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    }
    return _m1;
}
@end
